<!DOCTYPE html>
<html>
  <head>
    <title>导航</title>
	  <meta charset="utf-8">
   <!--  <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no"> -->
    <meta name="keywords" content="keyword1,keyword2,keyword3">
    <meta name="description" content="this is my page">
    <meta name="content-type" content="text/html; charset=UTF-8">
      <script src="static/js/jquery-1.11.2.min.js"></script>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=slQh6wYeGi2K2Lnrk7pfZHyVUfdjVdtD"></script>
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->

  </head>
    <style>
   	#up-map-div{
 width:100%; 
height:10%;
top:30px;
/* left:30px; */
z-index:9999;
/* border:1px solid white; */
background-color:#FFFFFF;
} 
.BMap_bubble_title p a{display:none}
.BMap_shadow {
display:none;}
.BMapLabel{
background-color: #5085F9;
margin-left:20px;
/* color:white; */

 }
  .anchorBL{
  display:none;
  }
  .anchorBL span{
  display:none;
  }
  div .BMap_pop{
  display:none;
  }
  </style>
  <body style="margin:0px">
  <!-- <div>
	  <div>
	  		<div><span>我的位置：</span><input id="start" type="text" placeholder="我的位置" value ="我的位置"/></div>
	  		<div><span>我的位置：</span><input id="end1" type="text" placeholder="输入终点" value ="建国路79号"/></div>
	  		<div><button id="result" type="button" value="搜索">搜索</button></div>
	  </div>
	  <div id="allmap" style="position: absolute;height:100%;width:100%"></div>
	   	<div id="r-result"></div>
	 </div> -->
   <div style="height:100%;width:100%;">
  	  <div id = "up-map-div" style="position:absolute;">
  		 <div style="margin-left:0%;height:100%;width:100%;position:absolute;">
	  		<span style="margin-left:20px;font-size:30px;">输入起点:</span><input id="start" style="margin-left:20px;width:50%;marign-top:10px;font-size:30px;height:30%;margin-top:10px;"  placeholder="我的位置" value ="我的位置"></input><br />
	  		<span  style="margin-left:20px;font-size:30px;">输入终点:</span><input id="end1" style="margin-left:20px;width:50%;marign-top:10px;font-size:30px;height:30%;margin-top:10px;" placeholder="输入终点" value="建国路79号"></input>
  		 </div>
  		 <div style="right:10%;margin-top: 5%;position:absolute;">
  		 	<button id="result" style="font-size:25px;height:80px;width:120px;" type="button" value="导航">导航</button>
  		 </div>
  	</div>  
   	<div id="allmap" style="position: absolute;height:100%;width:100%"></div>
   	 <div id="r-result"></div>
   	</div>
  </body>

  <script>
  	var url=document.URL;
  	if(url.lastIndexOf("?")>0){        
  		para=url.substring(url.lastIndexOf("?")+1,url.length);	
  		var arr=para.split("&");
  		if(arr.length==1){
  			var commname = decodeURI(arr[0].split("=")[1].replace("#",""));		
  		 } 
  		}
  	$("#end1").val(commname);
	var temp;
	// 百度地图API功能
	var map = new BMap.Map("allmap");
	// 左上角，添加比例尺
	var top_left_control = new BMap.ScaleControl({anchor: BMAP_ANCHOR_TOP_LEFT});
	//左上角，添加默认缩放平移控件
	var top_left_navigation = new BMap.NavigationControl();  
	map.addControl(top_left_navigation);
	map.setMaxZoom = 18;
	//添加滚轮放大、缩小
	//map.enableScrollWheelZoom(true);
	cr = new BMap.CopyrightControl({anchor: BMAP_ANCHOR_TOP_RIGHT});   //设置版权控件位置
	map.addControl(cr); //添加版权控件
	var geolocation1 = new BMap.Geolocation();
	geolocation1.getCurrentPosition(function(r) {
		if(this.getStatus() == BMAP_STATUS_SUCCESS) {
			var lng = r.point.lng;
			var lat = r.point.lat;
			//temp = lat+","+lng;
			 temp = point = new BMap.Point(lng, lat);
		} else {
			alert('failed' + this.getStatus());
		}
	}, {
		enableHighAccuracy: true
	})
	var driving;
	map.centerAndZoom(new BMap.Point(116.404, 39.915), 9);
	//三种驾车策略：最少时间，最短距离，避开高速
	var routePolicy = [BMAP_DRIVING_POLICY_LEAST_TIME,BMAP_DRIVING_POLICY_LEAST_DISTANCE,BMAP_DRIVING_POLICY_AVOID_HIGHWAYS];
	$("#result").click(function(){
		var start = $("#start").val();
		var end = $("#end1").val();
		 if(start == "我的位置"||start == ""){
			start = temp;
		} 
		 if(end == ""){
			 alert("请输入目的地！！！")
		 }
		map.clearOverlays(); 
		search(start,end,"0"); //0最少时间，1最短距离，2避开高速
		/*  driving.setSearchCompleteCallback(function(){});  */
		
	});
	
	function search(start,end,route){ 
		driving = new BMap.DrivingRoute(map, {renderOptions:{map: map, autoViewport: true }});
		driving.search(start,end);
		  driving.setSearchCompleteCallback(function(){ 
	            var pts = driving.getResults().getPlan(0).getRoute(0).getPath();    //通过驾车实例，获得一系列点的数组  
	      
	            var polyline = new BMap.Polyline(pts);       
	            map.addOverlay(polyline);  
	                
	        });   

	}

	
	
	
  </script>
</html>
